global Cabsorb "i.provaC#i.age i.year#i.age" /* Define set of dummies for panel of firms by province, age and time */
set scheme s1color

use "$data/EffectSubsidydataset.dta", clear
gen popM=1
foreach var in RAS_55_nfirms_age0 {
gen log`var'=log(`var')
}
*capture drop South 
*gen South=latitude<42

*tab South South2

*drop if regione=="ABRUZZO"

*DROP PARTIALLY TREATED PROVINCES OF CRATERE SISMICO
drop if provincia=="L'AQUILA"
drop if provincia=="TERAMO"
drop if provincia=="RIETI"
drop if provincia=="MACERATA"
drop if provincia=="ASCOLI PICENO"
drop if provincia=="PERUGIA"
drop if provincia=="TERNI"
*
**************************************************
 * RESTO AL SUD APPLIES to all firms in South of Italy plus following provinces
* Enterpreneurs and start-ups should be created after 21/06/2017
* So First treatment year is 2017 
 *drop CENTRO
 
 *drop if  AREA_GEO ==3
 
 
 /*
 La  lista completa dei 140 Comuni colpiti e danneggiati dal sisma in Centro Italia cui spetteranno gli aiuti ed i rimborsi previsti dal decreto legge terremoto. 

L’elenco dei Comuni 140 comuni divisi per regione:

Abruzzo
Barete (Aq); Cagnano Amiterno (Aq); Campli (TE) Campotosto (AQ); Capitignano (AQ); Castelcastagna (Te); Castelli (TE); Civitella del Tronto (TE);  Colledara (Te); Cortino (TE); Crognaleto (TE); Fano Adriano (Te). Farindola (Pe); Isola del Gran Sasso (Te); Montereale (AQ); Montorio al Vomano (TE); Pietracamela (Te) Pizzoli (Aq); Rocca Santa Maria (TE); Teramo; Torricella Sicura (TE); Tossicia (TE); Valle Castellana (TE).

Lazio
Accumoli (RI); Amatrice (RI); Antrodoco (RI); Borbona (RI); Borgo Velino (RI); Cantalice (RI); Castel Sant’Angelo (RI); Cittaducale (RI); Cittareale (RI); Leonessa (RI); Micigliano (RI); Poggio Bustone (RI) Posta (RI); Rieti;  Rivodutri (RI).

Marche
Acquacanina (MC); Acquasanta Terme (AP); Amandola (FM); Apiro (MC); Appignano del Tronto (AP);
Arquata del Tronto (AP); Ascoli Piceno; Belforte del Chienti (MC); Belmonte Piceno (FM); Bolognola (MC);
Caldarola (MC); Camerino (MC); Camporotondo di Fiastrone (MC); Castel di Lama (AP); Castelraimondo (MC);
Castelsantangelo sul Nera (MC); Castignano (AP); Castorano (AP); Cerreto D’esi (AN); Cessapalombo (MC);
Cingoli (MC); Colli del Tronto (AP); Colmurano (MC); Comunanza (AP); Corridonia (MC); Cossignano (AP);
Esanatoglia (MC); Fabriano (AN); Falerone (FM); Fiastra (MC); Fiordimonte (MC); Fiuminata (MC);
Folignano (AP); Force (AP); Gagliole (MC); Gualdo (MC); Loro Piceno (MC);  Macerata; Maltignano (AP);
Massa Fermana (FM); Matelica (MC); Mogliano (MC); Monsapietro Morico (FM); Montalto delle Marche (AP);
Montappone (FM); Monte Rinaldo (FM); Monte San Martino (MC); Monte Vidon Corrado (FM);
Montecavallo (MC); Montedinove (AP);  Montefalcone Appennino (FM); Montefortino (FM); Montegallo (AP);
Montegiorgio (FM); Monteleone (FM); Montelparo (FM); Montemonaco (AP);  Muccia (MC); Offida (AP);
Ortezzano (FM); Palmiano (AP); Penna San Giovanni (MC); Petriolo (MC); Pieve Torina (MC);
Pievebovigliana (MC);  Pioraco (MC); Poggio San Vicino (MC);  Pollenza (MC); Ripe San Ginesio (MC);
Roccafluvione (AP); Rotella (AP); San Ginesio (MC); San Severino Marche (MC); Santa Vittoria in Matenano (FM);
Sant’Angelo in Pontano (MC); Sarnano (MC); Sefro (MC); Serrapetrona (MC); Serravalle del Chienti (MC);
Servigliano (FM); Smerillo (FM); Tolentino (MC); Treia (MC); Urbisaglia (MC); Ussita (MC); Venarotta (AP);
Visso (MC).

Umbria
Arrone (TR); Cascia (PG); Cerreto di Spoleto (PG); Ferentillo (TR); Montefranco (TR); Monteleone di Spoleto (PG); Norcia (PG); Poggiodomo (PG); Polino (TR); Preci (PG); Sant’Anatolia di Narco (PG); Scheggino (PG); Sellano (PG); Spoleto (PG); Vallo di Nera (PG).
*/ 

*FIRT TREATED PROVINCES ARE IN 2017
gen Post=year>=2017
gen SouthPost=South*Post

*egen totalN=total(old_RAS_nfirms_age0), by(year South)
*egen totalN2=total(RAS_55_nfirms_age0), by(year South)
*bysort year: sum totalN2 if South==1


preserve
collapse (sum) RAS_55_nfirms_age0, by(South year)
drop if year<2010
bysort year: sum RAS_55_nfirms_age0 if South==1
sum RAS_55_nfirms_age0 if year==2020 & South==1
* 11000-14000 new firms per year in South if we focus on entrepreneur with less than 56 years of age
* 21000-25000 new firms per year in South if we focus on all entrepreneurs without any age restriction
restore

**********************************************
* BUSINESS CREATION
*Effect on Business creation
*keep if year>2014

preserve

*[aw=popM]
label variable SouthPost "Eligible-to-Subsidy"
label variable logRAS_55_nfirms_age0 "Creation"
reghdfe logRAS_55_nfirms_age0 SouthPost , absorb(provincia year)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
*local Nobs :  di %13.0fc e(N)
local Nobbs= e(N) 
sleep 500
outreg2 using "$tables/EffectSubsidy.tex", replace tex(fragment)  addtext($ R^2$, `R2', Province dummy, "Y", Year dummy, "Y", Age dummy, "N", Province $\times$ Age dummy, "N", Year $\times$ Age dummy, "N") ///
nocons label nor2 keep(SouthPost)  bdec(2) rdec(2) ///
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)     nonotes 

reghdfe logRAS_55_nfirms_age0 SouthPost, absorb(provincia year)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tablesSlide/EffectSubsidySLIDE.tex", replace tex(fragment) addtext($ R^2$, `R2', Province dummy, "Y", Year dummy, "Y", Age dummy, "N", Province $\times$ Age dummy, "N", Year $\times$ Age dummy, "N") /// 
 nocons noobs label nor2 keep(SouthPost) ///
sortvar(inactive) bdec(2) rdec(2) alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2) 

restore





preserve
***********************************************************
*CHECK PAALLEL TREND Byear
*foreach num in 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 {

gen d2010=year==2010
gen d2011=year==2011
gen d2012=year==2012
gen d2013=year==2013
gen d2014=year==2014
*gen d2014=year==2013|year==2014
gen d2015=year==2015
gen d2016=year==2016
gen d2017=year==2017
gen d2018=year==2018
gen d2019=year==2019
gen d2020=year==2020

foreach num in 2010 2011 2012 2013  2014 2015 2017 2018 2019 2020 {
*foreach num in 2010 2011 2012  2014 2015 2017 2018 2019 2020 {

gen South`num'=South*d`num'
}



*keep if year>2014
reghdfe logRAS_55_nfirms_age0 South20*, absorb(provincia year)



/* 
gen Byear=2010 if year==2010
replace Byear=2012 if year==2011|year==2012
replace Byear=2014 if year==2013|year==2014
replace Byear=2016 if year==2015|year==2016
replace Byear=2017 if year==2017
replace Byear=2018 if year==2018
replace Byear=2019 if year==2019
replace Byear=2020 if year==2020
*/

gen estimate=0 if year==2016
gen stderr=0 if year==2016
foreach num in 2010 2011 2012 2013 2014 2015 2017 2018 2019 2020 {
*foreach num in 2010 2011 2012 2014 2015 2017 2018 2019 2020 {
replace estimate=_b[South`num'] if year==`num'
replace stderr=_se[South`num'] if year==`num'
}

*replace estimate=_b[South2014] if year==2013
*replace stderr=_se[South2014] if year==2013


collapse estimate stderr, by(year)
gen Byear=year
qui gen sign=stderr*1.654
qui gen min90=estimate-sign
qui gen max90=estimate+sign
qui replace sign=stderr*1.96
qui gen min95=estimate-sign
qui gen max95=estimate+sign

keep if Byear>=2010

*Grafh with Claudio's layout
twoway rcap min95 max95 Byear if Byear>2016, color(red*0.2) lpattern(solid) lwidth(medium) ||rcap min90 max90 Byear if Byear>2016, color(red*0.45) lpattern(solid) lwidth(medthick) ///
|| connected estimate Byear if Byear>=2016 & Byear<=2017, graphregion(color(white)) lpattern(dot) lcolor(gs0) lwidth(thick) ///
 || connected estimate Byear if Byear>2016, graphregion(color(white)) lpattern(dash) lcolor(red) mcolor(red) lwidth(vthick) msize(vlarge)  ///
|| rcap min95 max95 Byear if Byear<=2016, color(blue*0.4) lpattern(solid) lwidth(medthick) ||rcap min90 max90 Byear if Byear<=2016, color(blue*1.15) lpattern(solid) lwidth(medthick) ///
 || connected estimate Byear if Byear<=2016, graphregion(color(white)) lpattern(dash) lcolor(blue) mcolor(blue) lwidth(vthick) msize(vlarge)  ///
 ylabel(-0.1 (0.05) 0.2, grid) ytitle("Coefficient", size(medsmall) height(4)) xlabel(2010(1)2020) legend(off) yline(0.00, lc(gs2) lpattern(solid) lwidth(thick)) title("") xtitle("Year", size(medsmall) height(4))  xline(2016, lcolor(gs2) lwidth(thick) lpattern(solid))
gr export "$figures/BCsubsidy55.pdf" , replace 
gr export "$tablesSlide/BCsubsidy55.pdf" , replace

restore




************************************************************
*CALCULATE LEVERAGE RATIO, PRDUCTIVITY & EXIT RATE
*Calculate Leverage
*va debfin e dipxva
foreach num in 0 1 2 3 4 5 6 7 8 9 10 11 {
*Leverage
gen RAS_55_lev_age`num'=RAS_55_debfin_age`num'/RAS_55_va_age`num'

*Productivity
gen RAS_55_prod_age`num'=log(RAS_55_va_age`num'/RAS_55_dipxva_age`num')
*Calculate Exit Rate
gen RAS_55_exit_age`num'=(RAS_55_nfirms_ex_age`num'/RAS_55_nfirms_age`num')*100

*Calculate employment size
gen RAS_55_lsize_age`num'=log(RAS_55_dip_age`num'/RAS_55_nfirms_age`num')
}


************************************************************************************
*CONSTRUCT PANEL BY PROVINCE AGE AND TIME
keep if year>=2010
keep year provincia popM South RAS_55_exit*  RAS_55_lsize*   RAS_55_lev_age*  RAS_55_prod_age*
egen  id=group(year provincia)

bysort year: sum RAS_55_exit_age* RAS_55_lev_age* RAS_55_prod_age* RAS_55_lsize_age*



reshape long RAS_55_exit_age  RAS_55_lsize_age  RAS_55_lev_age  RAS_55_prod_age, i(id) j(age)
replace popM=1
*keep if RAS_55_exit_age!=. &  RAS_55_lsize_age!=. & RAS_55_lev_age!=. & RAS_55_prod_age!=. 


* DEFINE FIRMS TREATED THROUGH SUBSIDY
gen post=1 if year==2017 & age==0
replace post=1 if year==2018 & age==0
replace post=1 if year==2018 & age==1
replace post=1 if year==2019 & age==0
replace post=1 if year==2019 & age==1
replace post=1 if year==2019 & age==2
replace post=1 if year==2020 & age==0
replace post=1 if year==2020 & age==1
replace post=1 if year==2020 & age==2
replace post=1 if year==2020 & age==3

replace post=0 if post==.
gen SouthPost=South*post
* DEFINE FIRMS TREATED THROUGH SHAKEOUT
gen shakeout=1 if year==2017 & age>=1
replace shakeout=1 if year==2018 & age>=2
replace shakeout=1 if year==2019 & age>=3
replace shakeout=1 if year==2020 & age>=4
replace shakeout=0 if shakeout==.
gen SouthShake=South*shakeout
label variable SouthPost "Eligible-to-Subsidy"
label variable SouthShake " South-Incumbent"
label variable  RAS_55_exit_age "Exit rate"
label variable  RAS_55_lev_age "Leverage"
label variable RAS_55_prod_age "Productivity"
label variable  RAS_55_lsize_age "Size"



drop if provincia=="VIBO VALENTIA"
egen provaC=group(provincia)

tab provaC


egen provaGPA=group(provaC age)
egen provaGYA=group(year age)
reghdfe RAS_55_exit_age SouthPost SouthShake , absorb(provaGPA provaGYA)

************************************
* EXIT RATE
************************************
preserve

/*
reghdfe RAS_55_exit_age SouthPost SouthShake , absorb($Cabsorb)
local R2= e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidy.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2) addtext(Age entrepreneur, "55", Province dummy, "Y", Year dummy, "Y", Age dummy, "Y", Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2) adec(2) addstat($ R^2$, `R2')

reghdfe RAS_55_exit_age SouthPost    SouthShake , absorb($Cabsorb)
local R2= e(r2)
sleep 500
outreg2 using "$tablesSlide/EffectSubsidySLIDE.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2) addtext(Age entrepreneur, "55", Province dummy, "Y", Year dummy, "Y", Age dummy, "Y", Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2) adec(2) addstat($ R^2$, `R2')
*/
reghdfe RAS_55_exit_age SouthPost SouthShake, absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidy.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2', Province dummy, "Y", Year dummy, "Y", Age dummy, "Y", Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2) 

reghdfe RAS_55_exit_age SouthPost    SouthShake , absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tablesSlide/EffectSubsidySLIDE.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2', Province dummy, "Y", Year dummy, "Y", Age dummy, "Y", Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)  

restore



preserve
***********************************************************
*CHECK PAALLEL TREND Byear
*foreach num in 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 {

gen d2010=year==2010
gen d2011=year==2011
gen d2012=year==2012
*gen d2014=year==2013|year==2014
gen d2013=year==2013
gen d2014=year==2014
gen d2015=year==2015
gen d2016=year==2016
gen d2017=year==2017
gen d2018=year==2018
gen d2019=year==2019
gen d2020=year==2020

*Drop year 2016
foreach num in 2010 2011 2012 2013  2014 2015 2017 2018 2019 2020 {
*foreach num in 2010 2011 2012  2014 2015 2017 2018 2019 2020 {
gen South`num'=South*d`num'
}

drop if year==2018 & age==1
drop if year==2019 & age==1
drop if year==2019 & age==2
drop if year==2020 & age==1
drop if year==2020 & age==2
drop if year==2020 & age==3

*reghdfe RAS_55_exit_age South20* SouthShake , absorb($Cabsorb)

reghdfe RAS_55_exit_age South20* SouthShake , absorb($Cabsorb)


/* 
gen Byear=2010 if year==2010
replace Byear=2012 if year==2011|year==2012
replace Byear=2014 if year==2013|year==2014
replace Byear=2016 if year==2015|year==2016
replace Byear=2017 if year==2017
replace Byear=2018 if year==2018
replace Byear=2019 if year==2019
replace Byear=2020 if year==2020
*/

gen estimate=0 if year==2016
gen stderr=0 if year==2016
foreach num in 2010 2011 2012 2013 2014 2015 2017 2018 2019 2020 {
replace estimate=_b[South`num'] if year==`num'
replace stderr=_se[South`num'] if year==`num'
}

*replace estimate=_b[South2014] if year==2013
*replace stderr=_se[South2014] if year==2013


collapse estimate stderr, by(year)
gen Byear=year
qui gen sign=stderr*1.654
qui gen min90=estimate-sign
qui gen max90=estimate+sign
qui replace sign=stderr*1.96
qui gen min95=estimate-sign
qui gen max95=estimate+sign

keep if Byear>=2010

*Grafh with Claudio's layout
twoway rcap min95 max95 Byear if Byear>2016, color(red*0.2) lpattern(solid) lwidth(medium) ||rcap min90 max90 Byear if Byear>2016, color(red*0.45) lpattern(solid) lwidth(medthick) ///
|| connected estimate Byear if Byear>=2016 & Byear<=2017, graphregion(color(white)) lpattern(dot) lcolor(gs0) lwidth(thick) ///
 || connected estimate Byear if Byear>2016, graphregion(color(white)) lpattern(dash) lcolor(red) mcolor(red) lwidth(vthick) msize(vlarge)  ///
|| rcap min95 max95 Byear if Byear<=2016, color(blue*0.4) lpattern(solid) lwidth(medthick) ||rcap min90 max90 Byear if Byear<=2016, color(blue*1.15) lpattern(solid) lwidth(medthick) ///
 || connected estimate Byear if Byear<=2016, graphregion(color(white)) lpattern(dash) lcolor(blue) mcolor(blue) lwidth(vthick) msize(vlarge)  ///
 ylabel(-2 (1) 3, grid) ytitle("Coefficient", size(medsmall) height(4)) xlabel(2010(1)2020) legend(off) yline(0.00, lc(gs2) lpattern(solid) lwidth(thick)) title("") xtitle("Year", size(medsmall) height(4))  xline(2016, lcolor(gs2) lwidth(thick) lpattern(solid))
gr export "$figures/Exitsubsidy55.pdf" , replace 
gr export "$tablesSlide/Exitsubsidy55.pdf" , replace

restore





**********************************************
*Leverage ratio
**********************************************
preserve
local `Gage' 55
/*
reghdfe RAS_`Gage'_lev_age SouthPost   SouthShake , absorb($Cabsorb)
local R2= e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidy.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2) addtext(Age entrepreneur, "`Gage'",  Province dummy, "Y", Year dummy, "Y", Age dummy, "Y",  Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2) adec(2) addstat($ R^2$, `R2')

reghdfe RAS_`Gage'_lev_age SouthPost    SouthShake , absorb($Cabsorb)
local R2= e(r2)
sleep 500
outreg2 using "$tablesSlide/EffectSubsidySLIDE.tex", append tex(fragment) nocons label nor2 keep(SouthPost  SouthShake) ///
 bdec(2) rdec(2)  addtext(Age entrepreneur, "`Gage'", Province dummy, "Y", Year dummy, "Y", Age dummy, "Y", Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2) adec(2)  addstat($ R^2$, `R2')
*/
reghdfe RAS_55_lev_age SouthPost   SouthShake , absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidy.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2', Province dummy, "Y", Year dummy, "Y", Age dummy, "Y",  Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)  

reghdfe RAS_55_lev_age SouthPost    SouthShake , absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tablesSlide/EffectSubsidySLIDE.tex", append tex(fragment) nocons label nor2 keep(SouthPost  SouthShake) ///
 bdec(2) rdec(2)  addtext($ R^2$, `R2', Province dummy, "Y", Year dummy, "Y", Age dummy, "Y", Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)   

restore



*sum RAS_55_lev_age, d

*stop

preserve
***********************************************************
*CHECK PAALLEL TREND Byear
*foreach num in 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 {

gen d2010=year==2010
gen d2011=year==2011
gen d2012=year==2012
*gen d2014=year==2013|year==2014
gen d2013=year==2013
gen d2014=year==2014
gen d2015=year==2015
gen d2016=year==2016
gen d2017=year==2017
gen d2018=year==2018
gen d2019=year==2019
gen d2020=year==2020

foreach num in 2010 2011 2012 2013  2014 2015 2017 2018 2019 2020 {
gen South`num'=South*d`num'
}

drop if year==2018 & age==1
drop if year==2019 & age==1
drop if year==2019 & age==2
drop if year==2020 & age==1
drop if year==2020 & age==2
drop if year==2020 & age==3

*reghdfe RAS_55_lev_age South20* SouthShake , absorb($Cabsorb)

reghdfe RAS_55_lev_age South20* SouthShake , absorb($Cabsorb)


/* 
gen Byear=2010 if year==2010
replace Byear=2012 if year==2011|year==2012
replace Byear=2014 if year==2013|year==2014
replace Byear=2016 if year==2015|year==2016
replace Byear=2017 if year==2017
replace Byear=2018 if year==2018
replace Byear=2019 if year==2019
replace Byear=2020 if year==2020
*/

gen estimate=0 if year==2016
gen stderr=0 if year==2016
foreach num in 2010 2011 2012 2013 2014 2015 2017 2018 2019 2020 {
replace estimate=_b[South`num'] if year==`num'
replace stderr=_se[South`num'] if year==`num'
}

*replace estimate=_b[South2014] if year==2013
*replace stderr=_se[South2014] if year==2013


collapse estimate stderr, by(year)
gen Byear=year
qui gen sign=stderr*1.654
qui gen min90=estimate-sign
qui gen max90=estimate+sign
qui replace sign=stderr*1.96
qui gen min95=estimate-sign
qui gen max95=estimate+sign

keep if Byear>=2010

*Grafh with Claudio's layout
twoway rcap min95 max95 Byear if Byear>2016, color(red*0.2) lpattern(solid) lwidth(medium) ||rcap min90 max90 Byear if Byear>2016, color(red*0.45) lpattern(solid) lwidth(medthick) ///
|| connected estimate Byear if Byear>=2016 & Byear<=2017, graphregion(color(white)) lpattern(dot) lcolor(gs0) lwidth(thick) ///
 || connected estimate Byear if Byear>2016, graphregion(color(white)) lpattern(dash) lcolor(red) mcolor(red) lwidth(vthick) msize(vlarge)  ///
|| rcap min95 max95 Byear if Byear<=2016, color(blue*0.4) lpattern(solid) lwidth(medthick) ||rcap min90 max90 Byear if Byear<=2016, color(blue*1.15) lpattern(solid) lwidth(medthick) ///
 || connected estimate Byear if Byear<=2016, graphregion(color(white)) lpattern(dash) lcolor(blue) mcolor(blue) lwidth(vthick) msize(vlarge)  ///
 ylabel(-0.2 (0.2) 0.6, grid) ytitle("Coefficient", size(medsmall) height(4)) xlabel(2010(1)2020) legend(off) yline(0.00, lc(gs2) lpattern(solid) lwidth(thick)) title("") xtitle("Year", size(medsmall) height(4))  xline(2016, lcolor(gs2) lwidth(thick) lpattern(solid))
gr export "$figures/Leveragesubsidy55.pdf" , replace 
gr export "$tablesSlide/Leveragesubsidy55.pdf" , replace

restore



*********************************************************
* LABOUR PRODUCTIVITY 

preserve
/*
reghdfe RAS_55_prod_age SouthPost  SouthShake , absorb($Cabsorb)
local R2= e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidy.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2)  addtext(Age entrepreneur, "55", Province dummy, "Y", Year dummy, "Y", Age dummy, "Y",  Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2) adec(2) addstat($ R^2$, `R2')

reghdfe RAS_55_prod_age SouthPost   SouthShake , absorb($Cabsorb)
local R2= e(r2)
sleep 500
outreg2 using "$tablesSlide/EffectSubsidySLIDE.tex", append tex(fragment) nocons label nor2 keep(SouthPost  SouthShake) ///
 bdec(2) rdec(2) addtext(Age entrepreneur, "55", Province dummy, "Y", Year dummy, "Y", Age dummy, "Y",  Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2) adec(2) addstat($ R^2$, `R2')
*/

reghdfe RAS_55_prod_age SouthPost  SouthShake , absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidy.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2)  addtext($ R^2$, `R2',  Province dummy, "Y", Year dummy, "Y", Age dummy, "Y",  Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)  

reghdfe RAS_55_prod_age SouthPost   SouthShake , absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tablesSlide/EffectSubsidySLIDE.tex", append tex(fragment) nocons label nor2 keep(SouthPost  SouthShake) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2',  Province dummy, "Y", Year dummy, "Y", Age dummy, "Y",  Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)  
restore





preserve
***********************************************************
*CHECK PAALLEL TREND Byear
*foreach num in 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 {

gen d2010=year==2010
gen d2011=year==2011
gen d2012=year==2012
gen d2014=year==2013|year==2014
*gen d2013=year==2013
*gen d2014=year==2014
gen d2015=year==2015
gen d2016=year==2016
gen d2017=year==2017
gen d2018=year==2018
gen d2019=year==2019
gen d2020=year==2020

*foreach num in 2010 2011 2012 2013  2014 2015 2017 2018 2019 2020 {
foreach num in 2010 2011 2012  2014 2015 2017 2018 2019 2020 {
gen South`num'=South*d`num'
}

drop if year==2018 & age==1
drop if year==2019 & age==1
drop if year==2019 & age==2
drop if year==2020 & age==1
drop if year==2020 & age==2
drop if year==2020 & age==3

*reghdfe RAS_55_lev_age South20* SouthShake , absorb($Cabsorb)

reghdfe RAS_55_prod_age South20* SouthShake , absorb($Cabsorb)


/* 
gen Byear=2010 if year==2010
replace Byear=2012 if year==2011|year==2012
replace Byear=2014 if year==2013|year==2014
replace Byear=2016 if year==2015|year==2016
replace Byear=2017 if year==2017
replace Byear=2018 if year==2018
replace Byear=2019 if year==2019
replace Byear=2020 if year==2020
*/

gen estimate=0 if year==2016
gen stderr=0 if year==2016
*foreach num in 2010 2011 2012 2013 2014 2015 2017 2018 2019 2020 {
foreach num in 2010 2011 2012 2014 2015 2017 2018 2019 2020 {
replace estimate=_b[South`num'] if year==`num'
replace stderr=_se[South`num'] if year==`num'
}

replace estimate=_b[South2014] if year==2013
replace stderr=_se[South2014] if year==2013


collapse estimate stderr, by(year)
gen Byear=year
qui gen sign=stderr*1.654
qui gen min90=estimate-sign
qui gen max90=estimate+sign
qui replace sign=stderr*1.96
qui gen min95=estimate-sign
qui gen max95=estimate+sign

keep if Byear>=2010

*Grafh with Claudio's layout
twoway rcap min95 max95 Byear if Byear>2016, color(red*0.2) lpattern(solid) lwidth(medium) ||rcap min90 max90 Byear if Byear>2016, color(red*0.45) lpattern(solid) lwidth(medthick) ///
|| connected estimate Byear if Byear>=2016 & Byear<=2017, graphregion(color(white)) lpattern(dot) lcolor(gs0) lwidth(thick) ///
 || connected estimate Byear if Byear>2016, graphregion(color(white)) lpattern(dash) lcolor(red) mcolor(red) lwidth(vthick) msize(vlarge)  ///
|| rcap min95 max95 Byear if Byear<=2016, color(blue*0.4) lpattern(solid) lwidth(medthick) ||rcap min90 max90 Byear if Byear<=2016, color(blue*1.15) lpattern(solid) lwidth(medthick) ///
 || connected estimate Byear if Byear<=2016, graphregion(color(white)) lpattern(dash) lcolor(blue) mcolor(blue) lwidth(vthick) msize(vlarge)  ///
 ylabel(-0.1 (0.05) 0.2, grid) ytitle("Coefficient", size(medsmall) height(4)) xlabel(2010(1)2020) legend(off) yline(0.00, lc(gs2) lpattern(solid) lwidth(thick)) title("") xtitle("Year", size(medsmall) height(4))  xline(2016, lcolor(gs2) lwidth(thick) lpattern(solid))
gr export "$figures/Prodsubsidy55.pdf" , replace 
gr export "$tablesSlide/Prodsubsidy55.pdf" , replace

restore

*stop


********************************
* EMPLOYMENT SIZE
preserve
/*
reghdfe RAS_55_lsize_age SouthPost   SouthShake , absorb($Cabsorb)
local R2= e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidy.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2) addtext(Age entrepreneur, "55", Province dummy, "Y", Year dummy, "Y", Age dummy, "Y",  Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2) adec(2) addstat($ R^2$, `R2')

reghdfe RAS_55_lsize_age SouthPost   SouthShake , absorb($Cabsorb)
local R2= e(r2)
sleep 500
outreg2 using "$tablesSlide/EffectSubsidySLIDE.tex", append tex(fragment) nocons label nor2 keep(SouthPost  SouthShake) ///
 bdec(2) rdec(2) addtext(Age entrepreneur, "55", Province dummy, "Y", Year dummy, "Y", Age dummy, "Y", Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2) adec(2) addstat($ R^2$, `R2')
*/
reghdfe RAS_55_lsize_age SouthPost   SouthShake , absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidy.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2',  Province dummy, "Y", Year dummy, "Y", Age dummy, "Y",  Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)  

reghdfe RAS_55_lsize_age SouthPost   SouthShake , absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tablesSlide/EffectSubsidySLIDE.tex", append tex(fragment) nocons label nor2 keep(SouthPost  SouthShake) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2',  Province dummy, "Y", Year dummy, "Y", Age dummy, "Y", Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2) 

restore


clear



*****************************************************
*CONSTRUCT DATASET for model simulated data
*Creation for North
clear
import delimited "$data/mass_entry_n.txt"
rename v1 Creation
rename v2 year
gen South=0 
label variable Creation "Creation"

save "$data/mass_entry_n.dta", replace
use "$data/mass_entry_n.dta", clear
save "$data/dataset_entry_n.dta", replace
gen provaC=1
save "$data/dataset_entry_n.dta", replace
foreach x of numlist 2/62{
use "$data/mass_entry_n.dta", clear
gen provaC=`x'
append using "$data/dataset_entry_n.dta"
sleep  500
save "$data/dataset_entry_n.dta", replace
}
save "$data/dataset_entry_n.dta", replace

*Creation for South
clear
import delimited "$data/mass_entry_s.txt"
rename v1 Creation
rename v2 year
gen South=1 
label variable Creation "Creation"

save "$data/mass_entry_s.dta", replace
use "$data/mass_entry_s.dta", clear
save "$data/dataset_entry_s.dta", replace
gen provaC=63
save "$data/dataset_entry_s.dta", replace
foreach x of numlist 64/95{
use "$data/mass_entry_s.dta", clear
gen provaC=`x'
append using "$data/dataset_entry_s.dta"
sleep 500
save "$data/dataset_entry_s.dta", replace
}
*Data SET creation
append using "$data/dataset_entry_n.dta"
save "$data/dataset_entryModel.dta", replace
*****************************************************
*CONSTRUCT DATASET for province age year simulated data
*Creation for North
clear
import delimited "$data/data_n.txt"
rename v1 nfirmsBEG
rename v2 nfirmsEND
rename v3 Totaldebt
rename v4 totalVA
rename v5 totalE
rename v6 age
rename v7 year

gen South=0 

save "$data/data_n.dta", replace
use "$data/data_n.dta", clear
save "$data/dataset_other_n.dta", replace
gen provaC=1
save "$data/dataset_other_n.dta", replace
foreach x of numlist 2/62{
use "$data/data_n.dta", clear
gen provaC=`x'
append using "$data/dataset_other_n.dta"
sleep 500
save "$data/dataset_other_n.dta", replace
}
save "$data/dataset_other_n.dta", replace

*Creation for South
clear
import delimited "$data/data_s.txt"
rename v1 nfirmsBEG
rename v2 nfirmsEND
rename v3 Totaldebt
rename v4 totalVA
rename v5 totalE
rename v6 age
rename v7 year
gen South=1 


save "$data/data_s.dta", replace
use "$data/data_s.dta", clear
save "$data/dataset_other_s.dta", replace
gen provaC=63
save "$data/dataset_other_s.dta", replace
foreach x of numlist 64/95{
use "$data/data_s.dta", clear
gen provaC=`x'
append using "$data/dataset_other_s.dta"
sleep 500
save "$data/dataset_other_s.dta", replace
}
*Data SET creation
append using "$data/dataset_other_n.dta"
save "$data/dataset_otherModel.dta", replace
*****************************************************
*Regression for business creation
*
use "$data/dataset_entryModel.dta",clear

*FIRT TREATED PROVINCES ARE IN 2017
gen Post=year>=2017
gen SouthPost=South*Post



gen Lcreation=log(Creation)
label variable SouthPost "Eligible-to-Subsidy"
label variable Lcreation "Creation"
reghdfe Lcreation SouthPost , absorb(provaC year)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidyMODEL.tex", replace tex(fragment) nocons label nor2 keep(SouthPost) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2', Province dummy, "Y", Year dummy, "Y", Age dummy, "N", Province $\times$ Age dummy, "N", Year $\times$ Age dummy, "N") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)   nonotes




*****************************************************
*Regression for other 4 variables
*
use "$data/dataset_otherModel.dta",clear

* DEFINE FIRMS TREATED THROUGH SUBSIDY
gen post=1 if year==2017 & age==0
replace post=1 if year==2018 & age==0
replace post=1 if year==2018 & age==1
replace post=1 if year==2019 & age==0
replace post=1 if year==2019 & age==1
replace post=1 if year==2019 & age==2
replace post=1 if year==2020 & age==0
replace post=1 if year==2020 & age==1
replace post=1 if year==2020 & age==2
replace post=1 if year==2020 & age==3

replace post=0 if post==.
gen SouthPost=South*post
* DEFINE FIRMS TREATED THROUGH SHAKEOUT
gen shakeout=1 if year==2017 & age>=1
replace shakeout=1 if year==2018 & age>=2
replace shakeout=1 if year==2019 & age>=3
replace shakeout=1 if year==2020 & age>=4
replace shakeout=0 if shakeout==.
gen SouthShake=South*shakeout
label variable SouthPost "Eligible-to-Subsidy"
label variable SouthShake " South-Incumbent"

gen  exit_age=(1-nfirmsEND/nfirmsBEG)*100
*gen  lev_age=log(Totaldebt/totalVA)
gen  lev_age=Totaldebt/totalVA
gen prod_age=log(totalVA/totalE) 
*gen  lev_age=log(Totaldebt)
*gen prod_age=log(totalVA) 

gen  lsize_age=log(totalE/nfirmsEND)

label variable  exit_age "Exit rate"
label variable  lev_age "Leverage"
label variable prod_age "Productivity"
label variable  lsize_age "Size"


reghdfe exit_age SouthPost SouthShake, absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidyModel.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2', Province dummy, "Y", Year dummy, "Y", Age dummy, "Y", Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)  

reghdfe lev_age SouthPost   SouthShake , absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidyModel.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2',  Province dummy, "Y", Year dummy, "Y", Age dummy, "Y",  Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)  

reghdfe prod_age SouthPost  SouthShake , absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidyModel.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2)  addtext($ R^2$, `R2',  Province dummy, "Y", Year dummy, "Y", Age dummy, "Y",  Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)  
reghdfe lsize_age SouthPost   SouthShake , absorb($Cabsorb)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EffectSubsidyModel.tex", append tex(fragment) nocons label nor2 keep(SouthPost SouthShake) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2',  Province dummy, "Y", Year dummy, "Y", Age dummy, "Y",  Province $\times$ Age dummy, "Y", Year $\times$ Age dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)  



sum  lev_age,d

clear all
